import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
import { productTypeList } from './Product.api';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '商品名称',
    align: 'center',
    dataIndex: 'name',
  },

  {
    title: '价格',
    align: 'center',
    dataIndex: 'price',
    width: 80,
  },
  // {
  //   title: '优惠价格',
  //   align: 'center',
  //   dataIndex: 'discountPrice',
  //   width: 80,
  // },
  {
    title: '大类',
    align: 'center',
    dataIndex: 'typeId_dictText',
    width: 50,
  },
  {
    title: '品类',
    align: 'center',
    dataIndex: 'category',
    width: 120,
  },
  // {
  //   title: '库存数量',
  //   align: 'center',
  //   dataIndex: 'inventory',
  // },
  {
    title: '展示图',
    align: 'center',
    dataIndex: 'img',
    customRender: render.renderImage,
    width: 150,
  },
  // {
  //   title: '品牌',
  //   align: 'center',
  //   dataIndex: 'brand',
  //   width: 70,
  // },
  // {
  //   title: '产地',
  //   align: 'center',
  //   dataIndex: 'placeOfProduction',
  //   width: 70,
  // },
  // {
  //   title: '储存方式',
  //   align: 'center',
  //   dataIndex: 'storageMethod',
  //   width: 70,
  // },

  {
    title: '销量',
    align: 'center',
    dataIndex: 'salesVolume',
    width: 60,
  },
  {
    title: '返积分',
    align: 'center',
    dataIndex: 'points',
    width: 60,
  },
  // {
  //   title: '商品详情内多图地址',
  //   align: 'center',
  //   dataIndex: 'imgInfo',
  //   customRender: render.renderImage,
  // },
  // {
  //   title: '产品描述',
  //   align: 'center',
  //   dataIndex: 'description',
  // },
  {
    title: '重量',
    align: 'center',
    dataIndex: 'weight',
    width: 60,
  },
  {
    title: '规格',
    align: 'center',
    dataIndex: 'specification',
    width: 80,
  },

  // {
  //   title: '保质期',
  //   align: 'center',
  //   dataIndex: 'expirationDate',
  // },
  // {
  //   title: '生产日期',
  //   align: 'center',
  //   dataIndex: 'dateInProduced',
  // },
  // {
  //   title: '进货时间',
  //   align: 'center',
  //   dataIndex: 'purchaseDate',
  // },
  // {
  //   title: '所属社区店',
  //   align: 'center',
  //   dataIndex: 'orgId',
  // },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status',
    width: 60,
    customRender: ({ text }) => {
      return text ? '上架' : '下架';
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '直供/特供',
    field: 'isSpecial',
    component: 'Select',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '直供', value: 0 },
        { label: '特供', value: 1 },
      ],
    },
  },
  {
    label: '大类',
    field: 'typeId',
    component: 'ApiSelect',
    componentProps: {
      api: productTypeList,
      resultField: 'records',
      labelField: 'name',
      valueField: 'id',
      params: { header: 1, column: 'sort', order: 'asc' },
    },
  },
  {
    label: '上架状态',
    field: 'status',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '上架', value: 1 },
        { label: '下架', value: 0 },
      ],
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '直供/特供',
    field: 'isSpecial',
    component: 'Select',
    componentProps: {
      options: [
        { label: '直供', value: 0 },
        { label: '特供', value: 1 },
      ],
    },
  },
  {
    label: '商品名称',
    field: 'name',
    component: 'InputTextArea',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入商品名称!' }];
    },
  },
  {
    label: '价格',
    field: 'price',
    component: 'InputNumber',
  },
  {
    label: '品类',
    field: 'category',
    component: 'Input',
  },
  {
    label: '规格',
    field: 'specification',
    component: 'JDictSelectTag',
    componentProps: {
      type: 'radioButton',
      dictCode: 'specifications',
    },
  },
  {
    label: '重量',
    field: 'weight',
    component: 'InputNumber',
  },
  // {
  //   label: '优惠价格',
  //   field: 'discountPrice',
  //   component: 'InputNumber',
  // },
  {
    label: '大类',
    field: 'typeId',
    component: 'ApiSelect',
    componentProps: {
      api: productTypeList,
      resultField: 'records',
      labelField: 'name',
      valueField: 'id',
      params: { header: 1, column: 'sort', order: 'asc' },
    },
  },
  // {
  //   label: '库存数量',
  //   field: 'inventory',
  //   component: 'InputNumber',
  // },
  {
    label: '图片地址',
    field: 'img',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 5,
    },
  },

  {
    label: '品牌',
    field: 'brand',
    component: 'Input',
  },

  {
    label: '产地',
    field: 'placeOfProduction',
    component: 'Input',
  },
  {
    label: '包装方式',
    field: 'packing',
    component: 'Input',
  },
  {
    label: '储存方式',
    field: 'storageMethod',
    component: 'Input',
  },
  {
    label: '返积分',
    field: 'points',
    component: 'InputNumber',
  },
  {
    label: '产品描述',
    field: 'description',
    component: 'InputTextArea',
  },
  {
    label: '详情多图',
    field: 'imgInfo',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 10,
    },
  },

  {
    label: '保质期',
    field: 'expirationDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '生产日期',
    field: 'dateInProduced',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '进货时间',
    field: 'purchaseDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  // {
  //   label: '所属社区店',
  //   field: 'orgId',
  //   component: 'Input',
  // },
  {
    label: '上架状态',
    field: 'status',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '上架', value: 1 },
        { label: '下架', value: 0 },
      ],
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: { title: '商品名称', order: 0, view: 'text', type: 'string' },
  specification: { title: '商品规格（重量）', order: 1, view: 'text', type: 'string' },
  price: { title: '原价格', order: 2, view: 'number', type: 'number' },
  discountPrice: { title: '优惠价格', order: 3, view: 'number', type: 'number' },
  typeId: { title: '类型id', order: 4, view: 'list', type: 'string', dictCode: '' },
  inventory: { title: '库存数量', order: 5, view: 'number', type: 'number' },
  img: { title: '图片地址', order: 6, view: 'image', type: 'string' },
  brand: { title: '品牌', order: 7, view: 'text', type: 'string' },
  placeOfProduction: { title: '产地', order: 8, view: 'text', type: 'string' },
  storageMethod: { title: '储存方式', order: 9, view: 'text', type: 'string' },
  category: { title: '品类', order: 10, view: 'text', type: 'string' },
  salesVolume: { title: '销量', order: 11, view: 'number', type: 'number' },
  points: { title: '积分', order: 12, view: 'number', type: 'number' },
  imgInfo: { title: '商品详情内多图地址', order: 13, view: 'image', type: 'string' },
  expirationDate: { title: '保质期', order: 14, view: 'datetime', type: 'string' },
  dateInProduced: { title: '生产日期', order: 15, view: 'datetime', type: 'string' },
  purchaseDate: { title: '进货时间', order: 16, view: 'datetime', type: 'string' },
  orgId: { title: '所属社区店', order: 17, view: 'text', type: 'string' },
  status: { title: '状态(1上架0下架)', order: 18, view: 'number', type: 'number' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
